﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VedioOnline.Tools.Dao;

namespace VedioOnline.Tools
{
    public class TableData
    {
        public string code { set; get; }
        public string msg { set; get; }
        public int count { set; get; }
        public List<Dictionary<string, object>> data { set; get; }

    }

    public class GetIpAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpContextBase context = filterContext.HttpContext;
            HttpRequestBase Request = context.Request;

            string result = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (string.IsNullOrEmpty(result))
            {
                result = Request.ServerVariables["REMOTE_ADDR"];
            }
            if (string.IsNullOrEmpty(result))
            {
                result = Request.UserHostAddress;
            }
            if (string.IsNullOrEmpty(result))
            {
                result  = "0.0.0.0";
            }

            Dictionary<string, object> Map = new Dictionary<string, object>()
            {
                ["IP"] = result,
                ["VisitTime"] = DateTime.Now.ToString(),
            };
            BaseDao dao = new BaseDao();
            dao.save("o_PV", Map);

        }
    }
}